﻿#pragma once
#include <vector>
class CaptureTool
{
public:

	CaptureTool();

	~CaptureTool();

	static CaptureTool& inst();

	// Image
	int GetValueFromImg(int x, int y);

	void GetValueFromImg(int x, int y, int& r, int& g, int &b, int& a);

	void FetchHandle();

	void ResetData();

	bool CaptureScrenn();

	bool IsWindowEnable();

	HWND GetWowHWnd();

	void EnumDisplayDevices();

	bool SetSelWindowIndex(int val);


	struct stWindow
	{
		std::string name;
		DWORD pid;
		HWND hwnd;

	};
	struct stWindowCompare
	{
		constexpr bool operator()(const stWindow &lhs, const stWindow &rhs) const
		{
			return lhs.hwnd < rhs.hwnd;
		}
	};
	//自定义结构体
	typedef struct StWindowSet
	{
		std::string name;
		std::vector<stWindow> vec_hwnd;
	}stWindowSet;
	StWindowSet& GetWindowSet();

	int GetSelWindowPid();
private:


	void CopyWhiteImg(int cap_begin_y, BITMAP &bitmap, int cap_begin_x);

	void CopyValueFromSource(int nWidht, int nHeight, int cap_begin_x, int cap_begin_y, HBITMAP hBitmap, BITMAP& bitmap);

	HWND ProceGetWoWHwnd();



	void GetScreenPixel(HWND wow_hwnd);

	void IsRealWhite(int nWidht, int nHeight, BITMAP& bitmap, int cap_begin_x, int cap_begin_y, HBITMAP hBitmap);

	bool IsPosWhiteImg(int y, BITMAP &bitmap, int x);

	bool IsCapWhiteImg();


private:
	// Screen

	HWND wow_hwnd_ = NULL;
	int avail_scr_x = 0;
	int avail_scr_y = 0;
	bool is_real_white_ = false;
	std::vector<unsigned char> avail_cap_;		// 获得的 64 * 64 图像
	std::vector<unsigned char> buff_cap_;		// 获得的 原始图像

	stWindowSet stWindowSet_;
	int sel_window_pid = 0;
};


BOOL SaveHwndToBmpFile(HWND hWnd, LPCTSTR lpszPath);